package com.aierkeji.b2c.service;

import org.springframework.transaction.annotation.Transactional;

import com.aierkeji.b2c.dao.BaseJPADao;

import java.io.Serializable;
import java.util.List;

public abstract class BaseService<T,ID extends Serializable> {
	
	public abstract BaseJPADao<T,ID> getBaseDao();
	
	@Transactional
	public void save(T entity){
		getBaseDao().save(entity);
	}
	
	@Transactional(readOnly=true)
	public List<T> findAll(){
		return getBaseDao().findAll();
	}
	
	@Transactional(readOnly=true)
	public T findById(ID id){
		return getBaseDao().findById(id).get();
	}
	
	@Transactional
	public void delete(T entity){
		getBaseDao().delete(entity);
	}

	@Transactional
	public void deleteById(ID id){
		getBaseDao().deleteById(id);
	}
}
